// Dom7
var $$ = Dom7;

// Framework7 App main instance
var app = new Framework7({
	root: '#app', // App root element
	id: 'io.yachtar.app', // App bundle ID
  	name: 'Yachtar', // App name
	theme: 'auto', // Automatic theme detection
	dialog: {
		// set default title for all dialog shortcuts
		title: '提示',
		// change default "OK" button text
		buttonOk: '确认',
	  }
});

// Init/Create main view
var mainView = app.views.create('.view', {
	url: '/'
});
var housedatas;
//var cardid = "330382199306097115";
var serialno = sessionStorage.getItem("serialno");
var givetype = sessionStorage.getItem("givetype");
var cardid = sessionStorage.getItem("cardid");
var cardname = sessionStorage.getItem("cardname");
var cardimg = sessionStorage.getItem("cardimg");
$(document).ready(function(){
	$("#cardname").val(cardname);
	$("#cardid").val(cardid);
	$("#cardimg").attr("src","data:image/png;base64,"+ cardimg );
	call_remote(REQUEST_TYPE830,{cardid:cardid,serialno:serialno,givetype:givetype},function(data){
		housedatas = data;
		if(data.length>0){
			for (var i = 0; i < data.length; i++) {
				var elem_li = document.createElement('li');
				elem_li.setAttribute("class", "li-list");
				var elem_div = document.createElement("div");
				elem_div.setAttribute("class", "imgdiv");
				if(data[i].ticketflag == "O"){
					elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:60px;'>"
						+"<div class='col-80' style='text-align: left; font-size:22px;height:60px;line-height:60px;'>"+data[i].location+"</div>"
						+"<div class='col-20' style='text-align: center; font-size:22px;height:60px;line-height:60px;'>未投票</div>"
						+"</div>";
				}else{
					elem_div.innerHTML = "<div class='row no-gap' style='width:100%;height:60px;'>"
						+"<div class='col-80' style='text-align: left; font-size:22px;height:60px;line-height:60px;'>"+data[i].location+"</div>"
						+"<div class='col-20' style='text-align: center; font-size:22px;height:60px;line-height:60px;'>已投票</div>"
						+"</div>";
				}
				document.getElementById('ul-list').appendChild(elem_li); 
				elem_li.appendChild(elem_div);
			}
		}else{
			var elem_li = document.createElement('li');
			elem_li.setAttribute("class", "li-list");
			elem_li.innerHTML = "无房屋信息";
		}
	});
});


//返回
$$('#backimg').on('click', function () {
	window.location.href = "../../plugin/vote/votedetail.html";
});


$$('#startvote').on('click', function () {
	if(housedatas.length > 0){
		window.location.href = "../../plugin/vote/startvote.html";
	}else{
		app.dialog.alert("无房屋信息，无法投票！");
	}
});